package org.agony2d.view 
{
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.system.Capabilities;
	import flash.ui.Mouse;
	import org.agony2d.view.core.Component;
	import org.agony2d.notify.Observer;
	import org.agony2d.core.ProcessManager
	import org.agony2d.debug.Logger;
	import org.agony2d.view.core.ComponentProxy;
	import org.agony2d.view.core.FusionComp;
	import org.agony2d.view.core.IComponent;
	import org.agony2d.view.core.IModule;
	import org.agony2d.view.core.UIManager;
	import org.agony2d.view.puppet.NineScalePuppet;
	import org.agony2d.view.puppet.supportClasses.ImagePuppetComp;
	import org.agony2d.view.puppet.supportClasses.PuppetComp;
	import org.agony2d.view.supportClasses.AbstractImageButton;
	import org.agony2d.view.supportClasses.AbstractMovieClipButton;
	
	import org.agony2d.core.agony_internal;
	use namespace agony_internal;
	
	/** Agony Mobile UI Facade
	 *  [◆◇]
	 * 		1. pressedElement
	 * 		2. hoveredElement
	 * 		3. interactive
	 *  [◆◆◇]
	 *		1. startup
	 * 		2. addImageButtonData
	 * 		3. addMovieClipButtonData
	 * 		4. cacheToString
	 * 
	 * 		5. addModule
	 * 		6. getModule
	 * 		7. killAllModules
	 * 
	 * 		8. addNullPressedListener
	 * 		9. removeNullPressedListener
	 * 		10.stopAllDrag
	 *  [■]
	 * 		a. ImagePuppet
	 * 		b. AnimatorPuppet
	 * 		c. NineScalePuppet
	 * 		d. LabelPuppet
	 * 		e. InputTextPuppet
	 * 		f. ShapePuppet
	 * 		g. DisplayObjectContainerPuppet
	 * 
	 * 		h. Fusion
	 * 		i. MultiFusion
	 * 		j. ScrollPane
	 * 		k. ScrollPane
	 * 		l. ScrollPane
	 * 		m. ScrollPane
	 * 		n. ScrollPane
	 * 		o. ScrollPane
	 */
final public class AgonyUI
{
	
	/** ◆按下的组件 */
	public static function get pressedElement() : IComponent { return UIManager.pressedElement }
	
	/** ◆◇触碰中的组件 */
	public static function get hoveredElement() : IComponent { return UIManager.hoveredElement }
	
	/** ◆◇总交互开关 */
	public static function get interactive() : Boolean { return UIManager.m_interactive }
	public static function set interactive( b:Boolean ) : void
	{
		UIManager.m_interactive = b 
		if (!b)
		{
			UIManager.reset()
		}
	}
	
	public static function cacheToString() : String 
	{ 
		return 'puppetComp:' + PuppetComp.cachedPuppetCompLength +
				'，imagePuppetComp:' + ImagePuppetComp.cachedImageLength +
				'，fusionComp:' + FusionComp.cachedFusionCompLength
	}
	
	/** ◆◆◇启动
	 *  @param	invalidWhenLeave	滑出组件后是否失效
	 *  @param	simulationWidth		模拟宽度
	 *  @param	simulationHeight	模拟高度
	 *  @param	landscape			landscape / portrait
	 */
	public static function startup( invalidWhenLeave:Boolean, simulationWidth:int, simulationHeight:int, landscape:Boolean = true, fullScreen:Boolean = true ) : void
	{
		if (m_uiManager)
		{
			Logger.reportError('AgonyUI', 'startup', 'AgonyUI has been started up !!')
			return
		}
		
		UIManager.m_invalidWhenLeave = invalidWhenLeave
		UIManager.m_stage = ComponentProxy.m_stage = ProcessManager.m_stage
		if (!ProcessManager.m_stage)
		{
			Logger.reportError('AgonyUI', 'constructor', '主引擎(Despair)未启动 !!');
		}
		
		m_uiManager = new UIManager()
		
		trace('======================= [ agony2d - mobileUI ] =======================');
		Logger.reportMessage('AgonyUI', "★mobileUI引擎启动..." +
							"设备dpi(" + Capabilities.screenDPI + ")...\n")
	}
	
	/** ◆◆◇加入画像按钮数据
	 *  @param	source
	 *  @param	dataName
	 *  @param	buttonType
	 */
	public static function addImageButtonData( source:*, dataName:String, buttonType:int ) : void
	{
		AbstractImageButton.addImageButtonData(source, dataName, buttonType)
	}
	
	/** ◆◆◇加入影片剪辑按钮数据
	 *  @param	source
	 *  @param	dataName
	 *  @param	buttonType
	 */
	public static function addMovieClipButtonData( source:*, dataName:String, buttonType:int = 17 ) : void
	{
		AbstractMovieClipButton.addMovieClipButtonData(source, dataName, buttonType)
	}
	
	/** ◆◆◇加入模块
	 *  @param	moduleName
	 *  @param	stateType
	 */
	public static function addModule( moduleName:String, stateType:Class ) : void
	{
		m_uiManager.addModule(moduleName, stateType)
	}
	
	/** ◆◆◇获取模块
	 *  @param	moduleName
	 */
	public static function getModule( moduleName:String ) : IModule
	{
		return m_uiManager.getModule(moduleName)
	}
	
	/** ◆◆◇削除全部面板
	 */
	public static function killAllModules() : void
	{
		m_uiManager.killAllModules()
	}
	
	/** ◆◆◇加入空按下侦听器
	 *  @param	listener
	 *  @param	priority
	 */
	public static function addNullPressedListener( listener:Function, priority:int = 0 ) : void
	{
		(m_uiManager.m_nullPressedObserver ||= Observer.getObserver()).addListener(listener, priority)
	}
	
	/** ◆◆◇移除空按下侦听器
	 *  @param	listener
	 */
	public static function removeNullPressedListener( listener:Function ) : void
	{
		if (!m_uiManager.m_nullPressedObserver.removeListener(listener))
		{
			m_uiManager.m_nullPressedObserver = null
		}
	}
	
	/** ◆◆◇停止全部拖动
	 */
	public static function stopAllDrag( fireEvent:Boolean = false ) : void
	{
		ComponentProxy.stopAllDrag(fireEvent)
	}
	
	
	agony_internal static var m_uiManager:UIManager
}
}